﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using Jy123.DBUtility;
namespace Jy123.BLL.User_Module
{
    /// <summary>
    /// 业务逻辑类User_Club 的摘要说明。
    /// </summary>
    public class User_Club
    {
        public User_Club()
        { }
        #region  成员方法

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Jy123.Model.User_Module.User_Club> GetModelList(string strWhere)
        {
            DataSet ds = GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }

        private DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ID,CName,Logo,CStatus,FUser,FJType,FLevel,FColor,FLine,Supporter,Skill,PhysicalFitness,LiveNess,Morale,Experience,Star,Coach,Equipment,Description,Assets,WinTimes,LoseTimes,Formation,RaceTimes,Rate,Form,UID,Cash ");
            strSql.Append(" FROM User_Club ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 返回好友的同类型组件
        /// </summary>
        /// <param name="FJType">组件类型</param>
        /// <param name="order">排序</param>
        /// <param name="userId">用户id</param>
        /// <returns>好友的同类型组件</returns>
        public List<Jy123.Model.User_Module.User_Club> GetFriendModelList(int FJType, string order, int userId)
        {
            StringBuilder strWhere = new StringBuilder();
            strWhere.AppendFormat("FJType = {0} ", FJType);
            strWhere.Append("AND FUser IN (");
            strWhere.Append("SELECT FFriend FROM User_Friend ");
            strWhere.AppendFormat("WHERE FUser = {0})", userId);
            if (!string.IsNullOrEmpty(order))
            {
                strWhere.Append(" ORDER BY "+order);
            }
            return GetModelList(strWhere.ToString());
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Jy123.Model.User_Module.User_Club> DataTableToList(DataTable dt)
        {
            List<Jy123.Model.User_Module.User_Club> modelList = new List<Jy123.Model.User_Module.User_Club>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Jy123.Model.User_Module.User_Club model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Jy123.Model.User_Module.User_Club();
                    if (dt.Rows[n]["ID"].ToString() != "")
                    {
                        model.ID = int.Parse(dt.Rows[n]["ID"].ToString());
                    }
                    model.CName = dt.Rows[n]["CName"].ToString();
                    model.Logo = dt.Rows[n]["Logo"].ToString();
                    if (dt.Rows[n]["CStatus"].ToString() != "")
                    {
                        model.CStatus = int.Parse(dt.Rows[n]["CStatus"].ToString());
                    }
                    if (dt.Rows[n]["FUser"].ToString() != "")
                    {
                        model.FUser = int.Parse(dt.Rows[n]["FUser"].ToString());
                    }
                    if (dt.Rows[n]["FJType"].ToString() != "")
                    {
                        model.FJType = int.Parse(dt.Rows[n]["FJType"].ToString());
                    }
                    if (dt.Rows[n]["FLevel"].ToString() != "")
                    {
                        model.FLevel = int.Parse(dt.Rows[n]["FLevel"].ToString());
                    }
                    if (dt.Rows[n]["FColor"].ToString() != "")
                    {
                        model.FColor = int.Parse(dt.Rows[n]["FColor"].ToString());
                    }
                    if (dt.Rows[n]["FLine"].ToString() != "")
                    {
                        model.FLine = int.Parse(dt.Rows[n]["FLine"].ToString());
                    }
                    if (dt.Rows[n]["Supporter"].ToString() != "")
                    {
                        model.Supporter = int.Parse(dt.Rows[n]["Supporter"].ToString());
                    }
                    if (dt.Rows[n]["Skill"].ToString() != "")
                    {
                        model.Skill = int.Parse(dt.Rows[n]["Skill"].ToString());
                    }
                    if (dt.Rows[n]["PhysicalFitness"].ToString() != "")
                    {
                        model.PhysicalFitness = int.Parse(dt.Rows[n]["PhysicalFitness"].ToString());
                    }
                    if (dt.Rows[n]["LiveNess"].ToString() != "")
                    {
                        model.LiveNess = int.Parse(dt.Rows[n]["LiveNess"].ToString());
                    }
                    if (dt.Rows[n]["Morale"].ToString() != "")
                    {
                        model.Morale = int.Parse(dt.Rows[n]["Morale"].ToString());
                    }
                    if (dt.Rows[n]["Experience"].ToString() != "")
                    {
                        model.Experience = int.Parse(dt.Rows[n]["Experience"].ToString());
                    }
                    if (dt.Rows[n]["Star"].ToString() != "")
                    {
                        if ((dt.Rows[n]["Star"].ToString() == "1") || (dt.Rows[n]["Star"].ToString().ToLower() == "true"))
                        {
                            model.Star = true;
                        }
                        else
                        {
                            model.Star = false;
                        }
                    }
                    if (dt.Rows[n]["Coach"].ToString() != "")
                    {
                        if ((dt.Rows[n]["Coach"].ToString() == "1") || (dt.Rows[n]["Coach"].ToString().ToLower() == "true"))
                        {
                            model.Coach = true;
                        }
                        else
                        {
                            model.Coach = false;
                        }
                    }
                    if (dt.Rows[n]["Equipment"].ToString() != "")
                    {
                        if ((dt.Rows[n]["Equipment"].ToString() == "1") || (dt.Rows[n]["Equipment"].ToString().ToLower() == "true"))
                        {
                            model.Equipment = true;
                        }
                        else
                        {
                            model.Equipment = false;
                        }
                    }
                    model.Description = dt.Rows[n]["Description"].ToString();
                    if (dt.Rows[n]["Assets"].ToString() != "")
                    {
                        model.Assets = decimal.Parse(dt.Rows[n]["Assets"].ToString());
                    }
                    if (dt.Rows[n]["WinTimes"].ToString() != "")
                    {
                        model.WinTimes = int.Parse(dt.Rows[n]["WinTimes"].ToString());
                    }
                    if (dt.Rows[n]["LoseTimes"].ToString() != "")
                    {
                        model.LoseTimes = int.Parse(dt.Rows[n]["LoseTimes"].ToString());
                    }
                    model.Formation = dt.Rows[n]["Formation"].ToString();
                    if (dt.Rows[n]["RaceTimes"].ToString() != "")
                    {
                        model.RaceTimes = int.Parse(dt.Rows[n]["RaceTimes"].ToString());
                    }
                    if (dt.Rows[n]["Rate"].ToString() != "")
                    {
                        model.Rate = int.Parse(dt.Rows[n]["Rate"].ToString());
                    }
                    if (dt.Rows[n]["Form"].ToString() != "")
                    {
                        model.Form = int.Parse(dt.Rows[n]["Form"].ToString());
                    }
                    if (dt.Rows[n]["UID"].ToString() != "")
                    {
                        model.UID = int.Parse(dt.Rows[n]["UID"].ToString());
                    }
                    if (dt.Rows[n]["Cash"].ToString() != "")
                    {
                        model.Cash = int.Parse(dt.Rows[n]["Cash"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }
        #endregion  成员方法
    }
}


